<template>
  <view 
    class="category-card"
    @tap="navigateToDetail"
    @mouseenter="onCardHover(true)"
    @mouseleave="onCardHover(false)"
    :class="{ 'category-highlighted': isActive }">
    <view class="card-content">
      <view class="category-header">
        <text class="category-title" :class="{ 'title-highlighted': isActive }">{{ category.title }}</text>
        <view class="category-circle" :style="{ borderColor: category.color }">
          <view class="category-dot" :style="{ backgroundColor: category.color }"></view>
        </view>
      </view>
      <text class="task-count" :class="{ 'text-highlighted': isActive }">{{ category.taskCount }}条清单</text>
      
      <!-- Checkmark animation (visible when active) -->
      <view class="checkmark-container" v-if="isActive">
        <view class="checkmark-circle">
          <view class="checkmark"></view>
        </view>
      </view>
      
      <view class="status-section">
        <view class="status-item completed">
          <view class="status-bg completed-bg"></view>
          <text class="status-text completed-text" :class="{ 'text-highlighted': isActive }">已完成 {{ category.completed }}</text>
        </view>
        <view class="status-item uncompleted">
          <view class="status-bg uncompleted-bg"></view>
          <text class="status-text uncompleted-text" :class="{ 'text-highlighted': isActive }">未完成 {{ category.uncompleted }}</text>
        </view>
      </view>
    </view>
  </view>
</template>

<script>
export default {
  name: 'CategoryCard',
  props: {
    category: {
      type: Object,
      required: true
    },
    isActive: {
      type: Boolean,
      default: false
    }
  },
  data() {
    return {
      showCheckmark: false
    }
  },
  methods: {
    onCardHover(isHovering) {
      this.showCheckmark = isHovering;
      this.$emit('hover', isHovering);
    },
    navigateToDetail() {
      // 通知父组件更新活动卡片
      this.$emit('card-click', this.category.id);
      
      // 跳转到详情页，并传递分类信息
      uni.navigateTo({
        url: `/pages/detail/detail?id=${this.category.id || 0}&title=${encodeURIComponent(this.category.title)}`
      });
    }
  }
}
</script>

<style>
.category-card {
  width: 330rpx;
  height: 330rpx;
  background-color: #FFFFFF;
  border-radius: 50rpx;
  margin-bottom: 30rpx;
  box-shadow: 0 6rpx 10rpx rgba(119, 102, 231, 0.08);
  position: relative;
  overflow: hidden;
  transition: all 0.3s ease;
}

.category-highlighted {
  background-color: rgba(254, 116, 139, 0.8);
}

.card-content {
  padding: 30rpx;
  height: 100%;
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
}

.category-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.category-title {
  font-size: 60rpx;
  font-weight: 700;
  line-height: 126rpx;
  color: #333333;
}

.title-highlighted {
  color: #FFFFFF;
}

.category-circle {
  width: 54rpx;
  height: 54rpx;
  border-radius: 50%;
  border: 1rpx solid;
  display: flex;
  justify-content: center;
  align-items: center;
}

.category-dot {
  width: 36rpx;
  height: 36rpx;
  border-radius: 50%;
}

.task-count {
  font-size: 30rpx;
  font-weight: 400;
  line-height: 57.4rpx;
  color: #666666;
  margin-top: 20rpx;
}

.text-highlighted {
  color: #FFFFFF;
}

/* Checkmark Animation */
.checkmark-container {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 120rpx;
  height: 120rpx;
  display: flex;
  justify-content: center;
  align-items: center;
  animation: fadeIn 0.3s ease-in-out;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.checkmark-circle {
  width: 120rpx;
  height: 120rpx;
  border-radius: 50%;
  border: 6rpx solid #FFFFFF;
  display: flex;
  justify-content: center;
  align-items: center;
}

.checkmark {
  width: 40rpx;
  height: 80rpx;
  border-right: 6rpx solid #FFFFFF;
  border-bottom: 6rpx solid #FFFFFF;
  transform: rotate(45deg) translate(-10rpx, -10rpx);
}

.status-section {
  margin-top: auto;
  display: flex;
  justify-content: space-between;
  width: 100%;
  flex-wrap: nowrap;
}

.status-item {
  position: relative;
  height: 63rpx;
  display: flex;
  align-items: center;
  padding: 0 10rpx;
  flex: 1;
  max-width: 48%;
}

.status-text {
  font-size: 26rpx;
  font-weight: 400;
  line-height: 40.6rpx;
  position: relative;
  z-index: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.completed-text {
  color: #1EBD85;
}

.uncompleted-text {
  color: #FE748B;
}

.status-bg {
  position: absolute;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  border-radius: 99rpx;
  opacity: 0.1;
}

.completed-bg {
  background-color: #1EBD85;
}

.uncompleted-bg {
  background-color: #FE748B;
}
</style>